<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="google" value="notranslate">
  <link rel="shortcut icon" href="static/favicon.ico">
  <title>北京哈工科教DouBao编程软件_V2.0.7</title>
  <script src="./static/axios.min.js"></script>
  <script>
    if (typeof (require) === 'function') {
      var baidu = require('baidu-aip-sdk');
      var path = require('path');
      var fs = require('fs');
      var Recorder   = require('js-audio-recorder')
      var {
        shell,
        ipcRenderer
      } = require('electron');
      const getProjectTitleFromFilename = fileInputFilename => {
        if (!fileInputFilename) return '';
        // only parse title with valid scratch project extensions
        // (.sb, .sb2, and .sb3)
        const matches = fileInputFilename.match(/^(.*)\.sb[23]?$/);
        if (!matches) return '';
        return matches[1].substring(0, 100); // truncate project title to max 100 chars
      }


      window.onload = async () => {
        const x = process.argv[process.argv.length - 1]
        try {
          if (path.extname(x) == '.sb3') {
            fs.accessSync(x, fs.constants.R_OK);
            fs.readFile(x, (err, file) => {
              vm.loadProject(file)
                .then(e => {
                  console.log(e)
                  try { // Can fail e.g. when GUI is loaded from static file (integration tests)
                    history.replaceState({}, document.title, '.');
                  } catch (err) {}
                })
                .catch(error => {
                  console.log(error)
                  // Reset the file input after project is loaded
                  // This is necessary in case the user wants to reload a project
                });
            });

            process.argv[process.argv.length - 1] = ""
          }
        } catch (err) {
          console.log(err)
        }
        document.addEventListener('drop', e => {
          e.preventDefault();
          e.stopPropagation();

          let fileToUpload = e.dataTransfer.files[0];
          const uploadedProjectTitle = getProjectTitleFromFilename(fileToUpload.name);
          if (!uploadedProjectTitle) return;
          readerx(fileToUpload);
        });
        document.addEventListener('dragover', function (e) {
          e.preventDefault();
          e.stopPropagation();
        });
      }
      var SerialPort = require('serialport');

      function readerx(fileToUpload) {
        let reader = new FileReader();
        reader.readAsArrayBuffer(fileToUpload)

        reader.onload = e => {
          console.log(reader.result)
          vm.loadProject(reader.result)
            .then(e => {
              console.log(e)
              try { // Can fail e.g. when GUI is loaded from static file (integration tests)
                history.replaceState({}, document.title, '.');
              } catch (err) {}
            })
            .catch(error => {
              console.log(error)
              // Reset the file input after project is loaded
              // This is necessary in case the user wants to reload a project
            });
        }
      }
    }
  </script>
  <style>
    #body .scratchCategoryMenuItemLabel {
      font-size: 13px !important;
    }

    #canvas {
      display: none;
    }

    #body .blocklyText {
      font-size: 18px !important;
    }
  </style>
</head>


<body id="body">
  <canvas width="480" height="360" id="canvas">

  </canvas>
  <div id="top" style="position: absolute;top: 12px;right: 14px;z-index: 8989;">
    <span style="font-size: 0.75rem;
        font-weight: bold;
        color: hsla(0, 100%, 100%, 1);">代码</span> &nbsp;
    <style>
      .el-switch__core:after {
        content: "";
        position: absolute;
        top: 1px;
        left: 1px;
        border-radius: 100%;
        transition: all .3s;
        width: 16px;
        height: 16px;
        background-color: #fff;
      }
    </style>
    <div role="switch" aria-checked="true" style="display: inline-flex;
        align-items: center;
        position: relative;
        font-size: 14px;
        line-height: 20px;
        height: 20px;
        vertical-align: middle;"><a href="/arduino.html" class="el-switch__core" style="width: 40px; border-color: rgb(19, 206, 102); background-color: rgb(19, 206, 102);    margin: 0;
            display: inline-block;
            position: relative;
            width: 40px;
            height: 20px;
            border: 1px solid #dcdfe6;
            outline: none;
            border-radius: 10px;
            box-sizing: border-box;
            cursor: pointer;
            transition: border-color .3s,background-color .3s;
            vertical-align: middle;"></a></div>
  </div>
  <script type="text/javascript" src="lib.min.js"></script>
  <script type="text/javascript" src="chunks/gui.js"></script>
<script type="text/javascript" src="lib.min.js"></script><script type="text/javascript" src="chunks/blocksonly.js"></script></body>

</html>